package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.PopItemBinding;
import sz.szsmk.citizencard.model.network.bean.response.QueryUserBindCardRes;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/8/9 16:13
 * description:
 */
public class PopRvAdapter extends RecyclerView.Adapter<PopRvAdapter.PopHolder> {

    private Context mContext;
    private TextView popTv;
    private ArrayList<String> itemViewData;
    public PopItemInterface popItemInterface;
    private TextView nickTv;
    private int type = 0;
    private List<QueryUserBindCardRes.UserCardExBean> cardName;

    public PopRvAdapter(Context context, int i) {
        mContext = context;
        type = i;
    }

    public void popItemOnclick(PopItemInterface popItemInterface) {
        this.popItemInterface = popItemInterface;
    }

    @Override
    public int getItemViewType(int position) {
        return R.layout.pop_item;
    }

    @Override
    public PopHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return PopHolder.creat(parent);
    }

    @Override
    public void onBindViewHolder(PopHolder holder, int position) {
        loadItemView(position, holder.binding);
    }

    private void loadItemView(final int position, PopItemBinding binding) {
        if (cardName != null) {
        }
        if (itemViewData != null) {
            binding.popItemTv.setText(itemViewData.get(position));
//            nickTv.setText(itemViewData.get(position));
        }
        binding.popItemTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (popItemInterface != null) {
                    popItemInterface.onClick(v, position);
                }
            }
        });
        if (type == 1) {
            binding.popItemNick.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public int getItemCount() {
        return null == itemViewData ? 0 : itemViewData.size();
    }

    public void setItemViewData(ArrayList<String> itemViewData) {
        this.itemViewData = itemViewData;
    }

    public void setCardName(List<QueryUserBindCardRes.UserCardExBean> cardName) {
        this.cardName = cardName;
    }

    public static class PopHolder extends RecyclerView.ViewHolder {
        private PopItemBinding binding;

        public static PopHolder creat(ViewGroup parent) {
            PopItemBinding binding = PopItemBinding
                    .inflate(LayoutInflater.from(parent.getContext()), parent, false);
            return new PopHolder(binding);
        }

        public PopHolder(PopItemBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }


    public interface PopItemInterface {
        public void onClick(View view, int position);
    }


}
